package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ConstructionAnnouncement;
import com.ruoyi.system.service.IConstructionAnnouncementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工公告Controller
 * 
 * @author ruoyi
 * @date 2021-06-22
 */
@RestController
@RequestMapping("/system/announcement")
public class ConstructionAnnouncementController extends BaseController
{
    @Autowired
    private IConstructionAnnouncementService constructionAnnouncementService;

    /**
     * 查询施工公告列表
     */
//    @PreAuthorize("@ss.hasPermi('system:announcement:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConstructionAnnouncement constructionAnnouncement)
    {
        startPage();
        List<ConstructionAnnouncement> list = constructionAnnouncementService.selectConstructionAnnouncementList(constructionAnnouncement);
        return getDataTable(list);
    }

    /**
     * 导出施工公告列表
     */
//    @PreAuthorize("@ss.hasPermi('system:announcement:export')")
    @Log(title = "施工公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConstructionAnnouncement constructionAnnouncement)
    {
        List<ConstructionAnnouncement> list = constructionAnnouncementService.selectConstructionAnnouncementList(constructionAnnouncement);
        ExcelUtil<ConstructionAnnouncement> util = new ExcelUtil<ConstructionAnnouncement>(ConstructionAnnouncement.class);
        return util.exportExcel(list, "announcement");
    }

    /**
     * 获取施工公告详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:announcement:query')")
    @GetMapping(value = "/{caId}")
    public AjaxResult getInfo(@PathVariable("caId") Long caId)
    {
        return AjaxResult.success(constructionAnnouncementService.selectConstructionAnnouncementById(caId));
    }

    /**
     * 新增施工公告
     */
//    @PreAuthorize("@ss.hasPermi('system:announcement:add')")
    @Log(title = "施工公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstructionAnnouncement constructionAnnouncement)
    {constructionAnnouncement.setCaCreatetime(new Date());
        return toAjax(constructionAnnouncementService.insertConstructionAnnouncement(constructionAnnouncement));
    }

    /**
     * 修改施工公告
     */
//    @PreAuthorize("@ss.hasPermi('system:announcement:edit')")
    @Log(title = "施工公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructionAnnouncement constructionAnnouncement)
    {
        return toAjax(constructionAnnouncementService.updateConstructionAnnouncement(constructionAnnouncement));
    }

    /**
     * 删除施工公告
     */
//    @PreAuthorize("@ss.hasPermi('system:announcement:remove')")
    @Log(title = "施工公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caIds}")
    public AjaxResult remove(@PathVariable Long[] caIds)
    {
        return toAjax(constructionAnnouncementService.deleteConstructionAnnouncementByIds(caIds));
    }
}
